<template>
  <div>

    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="请假类型" prop="type">
        <el-select v-model="form.type" placeholder="请选择请假类型">
          <el-option
            v-for="dict in dict.type.sys_leave_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input v-model="form.title" placeholder="请输入标题" />
      </el-form-item>
      <el-form-item label="原因" prop="reason">
        <el-input v-model="form.reason" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="开始时间" prop="leaveStartTime">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="form.leaveStartTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="leaveEndTime">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="form.leaveEndTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <!--<el-form-item label="请假时长" prop="totalTime">
        <el-input v-model="form.totalTime" readonly />
      </el-form-item>-->
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>
    <!--以下是审批字段-->
    <div>
      <el-form label-width="100px">
        <el-divider></el-divider>

        <el-form-item label="申请理由" prop="remark">
          <el-input v-model="comment" type="textarea" :value="comment" />
        </el-form-item>
      </el-form>
    </div>

    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <el-button type="primary" @click="complete">确定修改并重新提交</el-button>
      <el-button @click="chexiao">撤销申请</el-button>
    </div>


  </div>
</template>

<script>

import {getLeavebyBpmid, updateLeave} from "@/api/myoa/qjsq";
import request from "@/utils/request";

export default {
  name: "thtz",
  dicts: ['sys_leave_type'],
  props: {
    bpmid:{
      type: String,
    },
    type:{
      type: String,
    },
    row:{
      type:Object
    }
  },
  data() {
    return {
      form :{
        id: null,
        type: null,
        title: null,
        reason: null,
        leaveStartTime: null,
        leaveEndTime: null,
        totalTime: null,
        realityStartTime: null,
        realityEndTime: null,
        applyUserId: null,
        applyUserName: null,
        applyTime: null,
        instanceId: null,
        processKey: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      },
      comment:'调整完成，再次申请',
      pass:'true',
      rules: {},
    }
  },
  created() {
    getLeavebyBpmid(this.bpmid).then(re=>{
      this.form = re.data;
    })

    this.$parent.$parent.sptitle="重新申请";
  },
  watch: {
    pass: function(val) {
      this.comment = val === 'true' ? '同意' : '驳回';
    },
  },
  methods: {
    complete() {
      const data = {
        "taskId": this.row.taskId,
        "instanceId": this.row.instanceId,
        "bpmid":this.bpmid,
        "variables": JSON.stringify({
          "comment": this.comment,
          "pass": "true",
          "formData": this.row,
        })
      };
      updateLeave(this.form).then(re=>{

      });

      return request({
        url: '/leave/leave/complete',
        method: 'post',
        params: data
      }).then(response => {
        this.close();
        // 刷新待办事项列表
        this.$parent.$parent.$parent.$parent.$parent.$parent.getList();
        this.$modal.msgSuccess("操作成功");
      });

    },
    close: function () {
      this.$parent.$parent.opensp=false;
    },
    chexiao(){
      const data = {
        "taskId": this.row.taskId,
        "instanceId": this.row.instanceId,
        "bpmid":this.bpmid,
        "variables": JSON.stringify({
          "comment": this.comment,
          "pass": "false",
          "formData": this.row,
        }),
        "pass":"false"
      };

      return request({
        url: '/leave/leave/complete',
        method: 'post',
        params: data
      }).then(response => {
        this.close();
        // 刷新待办事项列表
        this.$parent.$parent.$parent.$parent.$parent.$parent.getList();
        this.$modal.msgSuccess("操作成功");
      });
    }
  }
};
</script>
